package com.example.template.ui.market.page;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.library.baseAdapters.BR;

import com.example.base.adapter.FragmentPagerAdapter;
import com.example.base.adapter.indicator.WrapIndicator;
import com.example.base.ui.BaseFragment;
import com.example.base.ui.viewbinding.DataBindingConfig;
import com.example.template.R;
import com.example.template.databinding.FragmentMarketBinding;

import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;

import java.util.Arrays;

public class MarketFragment extends BaseFragment {

    private FragmentMarketBinding binding;

    @Override
    protected void initViewModel() {

    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(R.layout.fragment_market, BR._all,null);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding = (FragmentMarketBinding) getBinding();

        String[] mTabs = getResources().getStringArray(R.array.market_tabs);

        FragmentPagerAdapter<BaseFragment> mPagerAdapter = new FragmentPagerAdapter<>(this);
        mPagerAdapter.addFragment(MarketListFragment.newInstance());
        mPagerAdapter.addFragment(MarketListFragment.newInstance());
        binding.viewPager.setAdapter(mPagerAdapter);

        CommonNavigator commonNavigator = new CommonNavigator(getContext());
        commonNavigator.setAdapter(new WrapIndicator(binding.viewPager,Arrays.asList(mTabs)));
        binding.magicIndicator.setNavigator(commonNavigator);
        ViewPagerHelper.bind(binding.magicIndicator, binding.viewPager);
    }
}